package com.tongji.showroom.utils
{
	import com.tongji.showroom.events.ShowRoomEvent;
	import com.tongji.showroom.utils.Showroom;
	import com.tongji.showroom.view.titleWindows.SingleFurnitureTitleWindow;
	import com.tongji.showroom.view.twoD.AddBitmap;
	
	import mx.collections.ArrayCollection;
	import mx.core.UIComponent;
	
	/**
	 * 
	 * @author chenzhongyuan
	 * 2011-11-3
	 */	
	
	public class Showroom
	{
		private var sceneAngle:Object = new Object();
		private var backGroundBitmap:AddBitmap;

		public function Showroom(uiComponent:UIComponent, obj:Object, angleData:int):void
		{
			var defaultScene:Object;
			var maxDepth:int = 0;
			
			//清除场景			
			while(uiComponent.numChildren > 0)
			{
				uiComponent.removeChildAt(0);
			}
			
			if (angleData == 0)
			{
				defaultScene = obj.SceneAngleList[0];
			}
			else
			{
				//根据angleData找到所要改变的角度
				for each (var angle:Object in obj.SceneAngleList)
				{
					if (angle.Jdid == angleData)
					{
						defaultScene = angle;
					}
				}	 
			}
			
			sceneAngle = defaultScene;
			backGroundBitmap = new AddBitmap(sceneAngle.Bgurl, ConstVariableInventory.PICTURE_WIDTH / 2, ConstVariableInventory.PICTURE_HEIGHT / 2)
			uiComponent.addChild(backGroundBitmap);
			
			for each(var sceneInfo1:Object in defaultScene.SceneInfoList)
			{
				if (sceneInfo1.depth > maxDepth)
					maxDepth = sceneInfo1.depth;
			}
						
			while (maxDepth > 0)
			{
				for each(var sceneInfo:Object in defaultScene.SceneInfoList)
				{		
					if (sceneInfo.depth == maxDepth)
					{
						var addBitmap:AddBitmap = new AddBitmap(sceneInfo.ProductUrl, sceneInfo.xAxis, sceneInfo.yAxis);	
						uiComponent.addChild(addBitmap);
						sceneInfo.sceneInfoBitmap = addBitmap;
						if(sceneInfo.sceneInfoVisible == null)
							sceneInfo.sceneInfoVisible = true;
						addBitmap.visible = sceneInfo.sceneInfoVisible;
						maxDepth--;
					}	
				}	
			}	
		}
	}
}